Remove, Clear a File Input

There is an extra step that needs to be made when clearing out an <input type='file'/> input in a ReactJS app. The easy way is to use the useRef hook.

function ExampleFileInput() {
  const ref = React.useRef();
  function handleClick() {
    ref.current.value = ""
  }
  return (
    <div className="App">
      <input type="file" ref={ref}/><br />
      <button type="button" onClick={handleClick}>Clear file</button>
    </div>
  );
}

Credits